{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Pmod ADC Reading Waveforms\n",
    "\n",
    "This demonstration shows how to use the Pmod ADC (AD2). \n",
    "\n",
    "The Pmod ADC, and an analog signal generator are required for this demonstration. \n",
    "\n",
    "In this demonstration, an analog waveform is generated using the Digilent Analog Discovery 2, and the Waveforms software:\n",
    "\n",
    "[Digilent Analog Discovery 2](http://store.digilentinc.com/analog-discovery-2-100msps-usb-oscilloscope-logic-analyzer-and-variable-power-supply/)\n",
    "\n",
    "<td> <img src=\"http://cdn6.bigcommerce.com/s-7gavg/products/468/images/2617/Analog_Discovery_2_obl_Academic_600__01249.1447804398.1280.1280.png\" alt=\"Drawing\" style=\"width: 250px;\"/> </td>\n",
    "\n",
    "[WaveForms 2015](https://reference.digilentinc.com/waveforms3#newest):\n",
    "\n",
    "<td> <img src=\"https://reference.digilentinc.com/_media/reference/software/waveforms/waveforms-3/waveforms3-0.png\" alt=\"Drawing\" style=\"width: 250px;\"/> </td>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "For the waveform to be displayed, we collect multiple points in each period. However, according to the Nyquist theorem, the sample rate only has to be $2\\times$ the frequency of the signal.\n",
    "\n",
    "The following block of code is just an example. For the Pmod ADC, the minimum delay between two samples is around $0.3\\,$ms (corresponding to a sampling period of $3\\,$kHz). So the maximum frequency of the input signal can be $1.5\\,$kHz.\n",
    "\n",
    "For the interface ID used in the following example, if the Pmod ADC is connected to interface PMODA, type in `PMODA`; if the Pmod ADC is connected to interface PMODB, type in `PMODB`.\n",
    "\n",
    "For the WaveForms configuration, this example uses the following parameters:\n",
    "\n",
    "| Wavegen Parameters | Configuration  |\n",
    "| ---------------------- |\n",
    "| Type           | Sine |\n",
    "| Amplitude      | 1V |\n",
    "| Offset         | 1V |\n",
    "| Symmetry       | 50% |\n",
    "| Phase          | 0  |\n",
    "\n",
    "Channel 0 (V1) on Pmod ADC is connected to port W1 on Digilent Analog Discovery 2."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Type in the interface ID used (PMODA or PMODB): PMODB\n",
      "Type in the frequency/Hz of the waveform: 200\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEICAYAAABYoZ8gAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHclJREFUeJzt3X2UXHWd5/H3p0OyY0OUgUTEJN3NGfEhyIOmN+sgCjgD\nG57MsONoMj3C7NHTBw/s6o7rimaPrDubmfW4M6soDttHswxLA4tCkJUnYRwmKCJ0kGcMxth5IpAG\nBAJhCDHf/ePeIpWiqruqUw/31v28zqlTVb/fvbd+davqW/f+ft97ryICMzMrjp5ON8DMzNrLgd/M\nrGAc+M3MCsaB38ysYBz4zcwKxoHfzKxgHPjNuoSk/ybpaUlPdrotlm0O/FY3SeOSXpb0oqSnJF0m\n6aC07g5JIenYinlWp+UnlZUtlHSDpOcl7ZD0j5KOL6sfSOd5sey1fiDplDraKEkbJD1ape4OSf+c\nvuYLktZKulDSv6iY7u2SvpsG0eclPSjpLyTNqLLMdZI+Vvb8/WnbK8t2SDpgqvZPl6Q+4LPAwoh4\nS6tex7qDA7816qyIOAh4LzAI/OeyuseBc0pPJB0K/D4wUVb2e8BPgIeAI4C3AquBH0r6/YrXOjh9\nrWOB24DVkv58ivZ9EPgd4M2S/mWV+gsiYjZwOEmgXAbcJEll7fsZsBk4OiLeBPwJsAiYXWV5a9LX\nLH/9X1Qp+2lE7J6i7fujD3gmIrY3OmMr/5Asmxz4bVoiYitwM/DusuJR4GNlW8bLSYL6rrJp/gtJ\nEFwREc9GxI6IuBj4P8BXarzWkxHx9XTer0ia7Ht7LnAtcH36uFb7X4qIO4APk/w5nZFW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cE48JuZ\nFcz/B+Q7cYG3FoRZAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2fa3f3d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from time import sleep\n",
    "from pynq.overlays.base import BaseOverlay\n",
    "from pynq.lib import Pmod_ADC\n",
    "\n",
    "base = BaseOverlay(\"base.bit\")\n",
    "\n",
    "\n",
    "if_id = input(\"Type in the interface ID used (PMODA or PMODB): \")\n",
    "if if_id.upper()=='PMODA':\n",
    "    adc = Pmod_ADC(base.PMODA)\n",
    "else:\n",
    "    adc = Pmod_ADC(base.PMODB)\n",
    "\n",
    "freq = int(input(\"Type in the frequency/Hz of the waveform: \"))\n",
    "period = 1/freq\n",
    "log_interval_us = 0\n",
    "\n",
    "# Assume Channel 0 is connected to the waveform generator\n",
    "adc.start_log(1,0,0,log_interval_us)\n",
    "sleep(3*period)\n",
    "log = adc.get_log()\n",
    "\n",
    "# Draw the figure\n",
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "plt.plot(range(len(log)), log, 'ro')\n",
    "plt.title('PMOD ADC Waveform')\n",
    "plt.axis([0, len(log), min(log), max(log)])\n",
    "plt.show()\n",
    "\n",
    "adc.reset()\n",
    "del adc,base"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
